#include <time.h>
#include "valuepair.h"
#include "lutil.h"

#ifndef _MAIN_H
#define _MAIN_H

typedef struct radius_packet_t {
  uint8_t	code;
  uint8_t	id;
  uint8_t	length[2];
  uint8_t	vector[16];
  uint8_t	data[1];
} radius_packet_t;

typedef struct radius_packet {
	int			sockfd;
	uint32_t		src_ipaddr;
	uint32_t		dst_ipaddr;
	u_short			src_port;
	u_short			dst_port;
	int			id;
	int			code;
	uint8_t			vector[16];
	int			timestamp;
	int			verified;
	uint8_t			*data;
	int			data_len;
	VALUE_PAIR		*vps;
} RADIUS_PACKET;

typedef struct auth_req {
#ifndef NDEBUG
	uint32_t		magic; /* for debugging only */
#endif
	RADIUS_PACKET		*packet;
	RADIUS_PACKET		*proxy;
	RADIUS_PACKET		*reply;
	RADIUS_PACKET		*proxy_reply;
	VALUE_PAIR		*config_items;
	VALUE_PAIR		*username;
	VALUE_PAIR		*password;
	char			secret[32];
	time_t			timestamp;
	int			number; /* internal server number */

	/* Could almost keep a const char * here instead of a _copy_ of the
	 * secret... but what if the RADCLIENT structure is freed because it was
	 * taken out of the config file and SIGHUPed? */
	char		proxysecret[32];
	int			proxy_is_replicate;
	int			proxy_try_count;
	time_t		proxy_next_try;

	int         simul_max;
	int         simul_count;
	int         simul_mpp; /* WEIRD: 1 is false, 2 is true */
	int			finished;
	void		*container;
} REQUEST;

/*
 *  Function handler for requests.
 */
typedef		int (*RAD_REQUEST_FUNP)(REQUEST *);

typedef struct radclient {
	uint32_t		ipaddr;
	uint32_t		netmask;
	char			longname[256];
	unsigned char			secret[32];
	char			shortname[32];
	struct radclient	*next;
} RADCLIENT;


typedef struct realm {
	char			realm[64];
	char			server[64];
	uint32_t		ipaddr;
	unsigned char			secret[32];
	int			auth_port;
	int			acct_port;
	int			striprealm;
	int			trusted;
	int			notrealm;
	struct realm		*next;
} REALM;

typedef struct pair_list {
	char			*name;
	VALUE_PAIR		*check;
	VALUE_PAIR		*reply;
	int			lineno;
	struct pair_list	*next;
	struct pair_list	*lastdefault;
} PAIR_LIST;

typedef struct main_config_t {
	int		log_auth;
	int		log_auth_badpass;
	int		log_auth_goodpass;
	int		do_usercollide;
	char 	*do_lower_user;
	char	*do_lower_pass;
	char	*do_nospace_user;
	char	*do_nospace_pass;
	char		*nospace_time;
} MAIN_CONFIG_T;

#endif 